<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of example_FVCOM_tsobc</title>
  <meta name="keywords" content="example_FVCOM_tsobc">
  <meta name="description" content="example file for dumping a file to force temperature and salinity at the open b.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">fvcom_prepro</a> &gt; example_FVCOM_tsobc.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for fvcom_prepro&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>example_FVCOM_tsobc
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>example file for dumping a file to force temperature and salinity at the open b.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function example_FVCOM_tsobc() </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> example file for dumping a file to force temperature and salinity at the open b.

 function example_FVCOM_tsobc()

 DESCRIPTION:
    Setup a sample FVCOM hydrographic open boundary forcing file

 INPUT
   
 OUTPUT:
    FVCOM hydrographic open boundary file

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="example.html" class="code" title="">example</a>	example demonstrating reading in a 2DM file and constructing a model</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function example_FVCOM_tsobc()</a>
0002 <span class="comment">% example file for dumping a file to force temperature and salinity at the open b.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% function example_FVCOM_tsobc()</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% DESCRIPTION:</span>
0007 <span class="comment">%    Setup a sample FVCOM hydrographic open boundary forcing file</span>
0008 <span class="comment">%</span>
0009 <span class="comment">% INPUT</span>
0010 <span class="comment">%</span>
0011 <span class="comment">% OUTPUT:</span>
0012 <span class="comment">%    FVCOM hydrographic open boundary file</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% Author(s):</span>
0015 <span class="comment">%    Geoff Cowles (University of Massachusetts Dartmouth)</span>
0016 <span class="comment">%</span>
0017 <span class="comment">% Revision history</span>
0018 <span class="comment">%</span>
0019 <span class="comment">%==============================================================================</span>
0020 
0021 warning off;
0022 
0023 
0024 subname = <span class="string">'example_FVCOM_tsobc'</span>;
0025 <span class="keyword">global</span> ftbverbose;
0026 <span class="keyword">if</span>(ftbverbose);
0027   fprintf(<span class="string">'\n'</span>)
0028   fprintf([<span class="string">'begin : '</span> subname <span class="string">'\n'</span>])
0029 <span class="keyword">end</span>;
0030 
0031 fvcom_bathy = <span class="string">'tst_dep.dat'</span>;
0032 fvcom_obc   = <span class="string">'tst_obc.dat'</span>;
0033 tsOBCFile = <span class="string">'tst_tsobc.nc'</span>;
0034 
0035 <span class="comment">%------------------------------------------------------------------------------</span>
0036 <span class="comment">% read in the FVCOM open boundary node data (need node numbers and dimension)</span>
0037 <span class="comment">%------------------------------------------------------------------------------</span>
0038 fid = fopen(fvcom_obc,<span class="string">'r'</span>);
0039 <span class="keyword">if</span>(fid  &lt; 0)
0040   error([<span class="string">'file: '</span> fvcom_obc <span class="string">' does not exist'</span>]);
0041 <span class="keyword">end</span>;
0042 C = textscan(fid, <span class="string">'%s %s %s %s %d'</span>, 1);
0043 nObc = C{5};
0044 obc_nodes = zeros(nObc,1);
0045 <span class="keyword">if</span>(ftbverbose); fprintf(<span class="string">'reading obc file\n'</span>); <span class="keyword">end</span>;
0046 <span class="keyword">if</span>(ftbverbose); fprintf(<span class="string">'# nodes %d\n'</span>,nObc); <span class="keyword">end</span>;
0047 <span class="keyword">for</span> i=1:nObc
0048   C = textscan(fid, <span class="string">'%d %d %d'</span>, 1);
0049   obc_nodes(i) = C{2};
0050 <span class="keyword">end</span>;
0051 
0052 <span class="keyword">if</span>(ftbverbose); fprintf(<span class="string">'obc reading complete\n'</span>);<span class="keyword">end</span>;
0053 
0054 <span class="comment">%------------------------------------------------------------------------------</span>
0055 <span class="comment">% read in the FVCOM bathymetry data (need bathymetry on open boundary nodes)</span>
0056 <span class="comment">%------------------------------------------------------------------------------</span>
0057 fid = fopen(fvcom_bathy,<span class="string">'r'</span>);
0058 <span class="keyword">if</span>(fid  &lt; 0)
0059   error([<span class="string">'file: '</span> fvcom_bathy <span class="string">' does not exist'</span>]);
0060 <span class="keyword">end</span>;
0061 C = textscan(fid, <span class="string">'%s %s %s %d'</span>, 1);
0062 Nverts = C{4};
0063 h = zeros(Nverts,1);
0064 <span class="keyword">if</span>(ftbverbose); fprintf(<span class="string">'reading bathymetry file\n'</span>);<span class="keyword">end</span>;
0065 <span class="keyword">if</span>(ftbverbose); fprintf(<span class="string">'# nodes %d\n'</span>,Nverts);<span class="keyword">end</span>;
0066 <span class="keyword">for</span> i=1:Nverts
0067   C = textscan(fid, <span class="string">'%f %f %f'</span>, 1);
0068   h(i) = C{3};
0069 <span class="keyword">end</span>;
0070 <span class="keyword">if</span>(ftbverbose); fprintf(<span class="string">'min depth %f max depth %f\n'</span>,min(h),max(h));<span class="keyword">end</span>;
0071 <span class="keyword">if</span>(ftbverbose); fprintf(<span class="string">'bathymetry reading complete\n'</span>);<span class="keyword">end</span>;
0072 fclose(fid);
0073 
0074 <span class="comment">%--------------------------------------------------------------</span>
0075 <span class="comment">% set variables for NetCDF file</span>
0076 <span class="comment">%--------------------------------------------------------------</span>
0077 
0078 <span class="comment">% extract bathymetry at open boundary nodes</span>
0079 obc_h = h(obc_nodes);
0080 
0081 <span class="comment">% time</span>
0082 time = 0:1:31.;
0083 nTimes = prod(size(time));
0084 
0085 <span class="comment">% set siglev/siglay</span>
0086 nSiglay = 10;
0087 nSiglev = 11;
0088 inc = 1./real(nSiglay);
0089 siglev = 0:-inc:-1;
0090 <span class="keyword">for</span> i=1:nSiglay
0091     siglay(i) = mean(siglev(i:i+1));
0092 <span class="keyword">end</span>;
0093 
0094 
0095 <span class="comment">% initialize temperature/salinity arrays</span>
0096 temp = zeros(nObc,nSiglay,nTimes);
0097 salt = zeros(nObc,nSiglay,nTimes);
0098 
0099 <span class="comment">% set variable temperature and salinity</span>
0100 <span class="keyword">for</span> i=1:nTimes
0101     obc_temp(i) = 18. + 2.*real(i-1)/nTimes;
0102     obc_salt(i) = 30. - 5.*real(i-1)/nTimes;
0103 <span class="keyword">end</span>;
0104 
0105 <span class="comment">%--------------------------------------------------------------</span>
0106 <span class="comment">% dump to netcdf file</span>
0107 <span class="comment">%--------------------------------------------------------------</span>
0108 
0109 <span class="comment">% open boundary forcing</span>
0110 nc = netcdf(tsOBCFile, <span class="string">'clobber'</span>);       
0111 
0112 nc.type = <span class="string">'FVCOM RIVER FORCING FILE'</span> ;
0113 nc.title = <span class="string">'simple open boundary hydrography test'</span>;   
0114 nc.type =  <span class="string">'FVCOM TIME SERIES OBC TS FILE'</span>; 
0115 nc.history = <span class="string">'generated using the fvcom-toolbox'</span>;
0116 
0117 <span class="comment">% dimensions</span>
0118 nc(<span class="string">'nobc'</span>) = nObc; 
0119 nc(<span class="string">'Datestrln'</span>) = 26; 
0120 nc(<span class="string">'time'</span>) = 0; 
0121 nc(<span class="string">'siglay'</span>) = nSiglay;
0122 nc(<span class="string">'siglev'</span>) = nSiglev;
0123 
0124 <span class="comment">% variables</span>
0125 nc{<span class="string">'river_names'</span>} = ncchar(<span class="string">'rivers'</span>, <span class="string">'namelen'</span>);
0126 
0127 nc{<span class="string">'time'</span>} = ncfloat(<span class="string">'time'</span>);
0128 nc{<span class="string">'time'</span>}.long_name = <span class="string">'time'</span>;  
0129 nc{<span class="string">'time'</span>}.units     = <span class="string">'days since 0.0'</span>;  
0130 nc{<span class="string">'time'</span>}.time_zone = <span class="string">'none'</span>;  
0131 
0132 nc{<span class="string">'Itime'</span>} = ncint(<span class="string">'time'</span>);
0133 nc{<span class="string">'Itime'</span>}.units     = <span class="string">'days since 0.0'</span>;  
0134 nc{<span class="string">'Itime'</span>}.time_zone = <span class="string">'none'</span>;  
0135 
0136 nc{<span class="string">'Itime2'</span>} = ncint(<span class="string">'time'</span>);
0137 nc{<span class="string">'Itime2'</span>}.units     = <span class="string">'msec since 00:00:00'</span>;
0138 nc{<span class="string">'Itime2'</span>}.time_zone = <span class="string">'none'</span>;  
0139 
0140 nc{<span class="string">'obc_nodes'</span>} = ncint(<span class="string">'nobc'</span>);
0141 nc{<span class="string">'obc_nodes'</span>}.long_name     = <span class="string">'Open Boundary Node Number'</span>;
0142 nc{<span class="string">'obc_nodes'</span>}.grid = <span class="string">'obc_grid'</span>;
0143 
0144 nc{<span class="string">'obc_h'</span>} = ncfloat(<span class="string">'nobc'</span>);
0145 nc{<span class="string">'obc_h'</span>}.long_name     = <span class="string">'ocean boundary depth'</span>;
0146 nc{<span class="string">'obc_h'</span>}.units = <span class="string">'m'</span>;
0147 nc{<span class="string">'obc_h'</span>}.grid  = <span class="string">'obc_grid'</span>;
0148 
0149 nc{<span class="string">'obc_siglev'</span>} = ncfloat(<span class="string">'siglev'</span>,<span class="string">'nobc'</span>);
0150 nc{<span class="string">'obc_siglev'</span>}.long_name     = <span class="string">'ocean_sigma/general_coordinate'</span>;
0151 nc{<span class="string">'obc_siglev'</span>}.grid  = <span class="string">'obc_grid'</span>;
0152 
0153 nc{<span class="string">'obc_siglay'</span>} = ncfloat(<span class="string">'siglay'</span>,<span class="string">'nobc'</span>);
0154 nc{<span class="string">'obc_siglay'</span>}.long_name     = <span class="string">'ocean_sigma/general_coordinate'</span>;
0155 nc{<span class="string">'obc_siglay'</span>}.grid  = <span class="string">'obc_grid'</span>;
0156 
0157 nc{<span class="string">'obc_temp'</span>} = ncfloat(<span class="string">'time'</span>,<span class="string">'siglay'</span>,<span class="string">'nobc'</span>);
0158 nc{<span class="string">'obc_temp'</span>}.long_name     = <span class="string">'sea_water_temperature'</span>;
0159 nc{<span class="string">'obc_temp'</span>}.units     = <span class="string">'Celsius'</span>;
0160 nc{<span class="string">'obc_temp'</span>}.grid  = <span class="string">'obc_grid'</span>;
0161 
0162 nc{<span class="string">'obc_salinity'</span>} = ncfloat(<span class="string">'time'</span>,<span class="string">'siglay'</span>,<span class="string">'nobc'</span>);
0163 nc{<span class="string">'obc_salinity'</span>}.long_name     = <span class="string">'sea_water_salinity'</span>;
0164 nc{<span class="string">'obc_salinity'</span>}.units     = <span class="string">'PSU'</span>;
0165 nc{<span class="string">'obc_salinity'</span>}.grid  = <span class="string">'obc_grid'</span>;
0166 
0167 nc{<span class="string">'obc_nodes'</span>}(:) = obc_nodes;
0168 nc{<span class="string">'obc_h'</span>}(:) = obc_h;
0169 <span class="keyword">for</span> i=1:nObc
0170     nc{<span class="string">'obc_siglev'</span>}(1:nSiglev,i) = siglev;
0171     nc{<span class="string">'obc_siglay'</span>}(1:nSiglay,i) = siglay;
0172 <span class="keyword">end</span>
0173 <span class="keyword">for</span> i=1:nTimes
0174     nc{<span class="string">'time'</span>}(i) = time(i);
0175     nc{<span class="string">'Itime'</span>}(i) = floor(time(i));
0176     nc{<span class="string">'Itime2'</span>}(i) = mod(time(i),1)*24*3600*1000.;
0177     nc{<span class="string">'obc_temp'</span>}(i,:,:) = obc_temp(i);
0178     nc{<span class="string">'obc_salinity'</span>}(i,:,:) = obc_salt(i);
0179 <span class="keyword">end</span>;
0180 
0181 nc = close(nc);    
0182 
0183 
0184 <span class="keyword">if</span>(ftbverbose); fprintf([<span class="string">'end   : '</span> subname <span class="string">'\n'</span>]);<span class="keyword">end</span>;</pre></div>
<hr><address>Generated on Wed 02-Nov-2011 21:58:00 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>